<style>
.main_content_wrap input[type="text"]{
    width:325px;
}
.left {
    float: left;
    margin: 5px;
}
.line1 {
    display: inline-block;
    width:950px;
    border-bottom: 1px solid #C3D0E1;
}
</style>

<div class="section">
        <?php
        $this->widget('AdminBankMenu', array(
            'bank_id' => $model->id,
            'bank_title' => $model->title,
        ));
        ?>
<?if(Yii::app()->user->hasFlash('opersuc')):?>
    <div class="messages green" title="Клик, чтобы скрыть" onclick="$(this).fadeOut();" style="cursor:pointer;float:left;clear: both;padding-right: 10px;">
        <span></span>
        <?=Yii::app()->user->getFlash('opersuc');?> 
    </div>
<? endif ?>
<?if(Yii::app()->user->hasFlash('operfail')):?>
    <div class="messages red" title="Клик, чтобы скрыть" onclick="$(this).fadeOut();" style="cursor:pointer;float:left;clear: both;padding-right: 10px;">
        <span></span>
        <?=Yii::app()->user->getFlash('operfail');?> 
    </div>
<? endif ?>
        <div class="box">
            <div class="title">
                <h2><?= $title?></h2>
                <span class="hide"></span>
            </div>
<div class="content forms">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'bankedit',
	'enableAjaxValidation'=>false,
)); ?>
	<div><font color="red"><?= Yii::t('app', 'Обязательные поля') ?>* </font></div>

	<?php echo $form->errorSummary($model); ?>

	<div class="line">
		<?php echo $form->labelEx($model,'title'); ?><font color="red">* </font>
		<?php echo $form->textField($model,'title', array('value' => $model->title, 'class'=>"medium") ); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>

	<div class="line">
		<?php echo $form->labelEx($model,'published'); ?>
		<?php echo $form->checkBox($model,'published', ($model->published == 1)?(array('checked' => 'checked')):array()); ?>
		<?php echo $form->error($model,'published'); ?>
	</div>

	<div class="line">
		<?php echo $form->labelEx($model,'moder_id'); ?>
		<?php echo $form->dropDownList($model,'moder_id', $moderators, array('value' => $model->moder_id)); ?>
		<?php echo $form->error($model,'moder_id'); ?>
	</div>
<!------------------------------------------------->

     <div class="upload_logo">
        <div style="margin-left:10px;"><span style="font-size:large;">Логотип:</span></div>
        <table >
            <tr>
                <td>
                    <div class="photo" id="bank_logo_on" style="<?=((empty($model->logo) || is_null($model->logo))?'display:none;':'')?>;">
                        <?=CHtml::image($model->getAttribute('logo'), $model->getAttributeLabel('logo'), array('width' => '170px', 'id' => 'bank_logo')) ?>
                    </div>
                </td>
                <td style="vertical-align:bottom;">
                    <div class="del_new_logo">
                        
                        <div id="bank_logo_on2" style="<?=((empty($model->logo) || is_null($model->logo))?'display:none;':'')?>;">
                            <?=CHtml::ajaxLink($model->getAttributeLabel('logo_delete'), 
                                                                        Yii::app()->createUrl('/banks/logodelete/id/'.$model->id), 
                                                                        array('type'=>'GET','data'=>array('id'=>$model->id),'success'=>'function(){$("#bank_logo_on").css("display","none");$("#bank_logo_on2").css("display","none");}'),
                                                                        array('onclick'=>'if (!confirm("Вы уверены что хотите удолить логотип ?")){return false;}',
                                                                            'class'=>'delete'))?><br>
                        </div>    
                        <div class="header">Добавить изображение:</div>
                            <div class="uploadinputsblock" >
                                            <? $this->widget('ext.EAjaxUpload.EAjaxUpload',
                                                array(
                                                    'id'=>'logo',
                                                    'config'=>array(
                                                            'action'=>Yii::app()->createUrl('/banks/logoupload/id/'.$model->id),
                                                            'allowedExtensions'=>array('jpg','gif','png','jpeg'),//array("jpg","jpeg","gif","exe","mov" and etc...
                                                            'sizeLimit'=>200*1024,// maximum file size in bytes
                                                            'minSizeLimit'=>10*1024,// minimum file size in bytes
                                                            //'onSubmit' => "js:function(id, fileName){ alert ('submit'); }",
                                                            //'onProgress' => "js:onProgress: function(id, fileName, loaded, total){ alert('progress') }",
                                                            'onComplete'=>"js:function(id, fileName, responseJSON){ 
                                                                                if (responseJSON.success){
                                                                                    alert(responseJSON.message);
                                                                                    $('#bank_logo').attr('src', responseJSON.filename);
                                                                                    $('#bank_logo_on').css('display','block');
                                                                                    $('#bank_logo_on2').css('display','block');
                                                                                }else{
                                                                                    alert(responseJSON.error);
                                                                                }
                                                                           }",
                                                            'onCancel' => "js:function(id, fileName){ alert('cancel') }",
                                                            'messages'=>array(
                                                                     'typeError'=>Yii::t('app', "{file} Имеет недопустимое расширение. Только {extensions} разрешены."),
                                                                     'sizeError'=>"{file} слишком большой, максимальный размер файла {sizeLimit}.",
                                                                     'minSizeError'=>"{file} слишком маленький, минимальный азмер файла {minSizeLimit}.",
                                                   //                  'emptyError'=>"{file} is empty, please select files again without it.",
                                                   //                  'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
                                                                    ),
                                                             'showMessage'=>"js:function(message){ alert(message); }" ,
                                                        'buttonName'=>'Добавить',
                                                        'width'=>'90px'
                                                  )
                                                )); ?>
                            <?php echo $form->error($model,'logo'); ?>
                            </div>
                        </div>
                     </td>
                </tr>
            </table>
         </div>
<!---------------------------end logo-->
            
	<div class="line1">
                    <div class="left">
                        <?php echo $form->labelEx($model,'req_post_address'); ?>
                        <?php echo $form->textField($model,'req_post_address', array('value' => $model->req_post_address, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'req_post_address'); ?>
                    </div>

                    <div class="left">
                        <?php echo $form->labelEx($model,'req_INN', array('style'=>"text-align: right;margin-right:20px;") ); ?>
                        <?php echo $form->textField($model,'req_INN', array('value' => $model->req_INN, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'req_INN'); ?>
                    </div>
        </div>
	<div class="line1">
                    <div class="left">
                        <?php echo $form->labelEx($model,'req_jurid_address'); ?>
                        <?php echo $form->textField($model,'req_jurid_address', array('value' => $model->req_jurid_address, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'req_jurid_address'); ?>
                    </div>

                    <div class="left">
                        <?php echo $form->labelEx($model,'req_phone', array('style'=>"text-align: right;margin-right:20px;") ); ?>
                        <?php echo $form->textField($model,'req_phone', array('value' => $model->req_phone, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'req_phone'); ?>
                    </div>
        </div>
	<div class="line1">
                    <div class="left">
                        <?php echo $form->labelEx($model,'email'); ?>
                        <?php echo $form->textField($model,'email', array('value' => $model->email, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'email'); ?>
                    </div>

                    <div class="left">
                        <?php echo $form->labelEx($model,'req_fax', array('style'=>"text-align: right;margin-right:20px;") ); ?>
                        <?php echo $form->textField($model,'req_fax', array('value' => $model->req_fax, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'req_fax'); ?>
                    </div>
        </div>
	<div class="line1">
                    <div class="left">
                        <?php echo $form->labelEx($model,'site'); ?>
                        <?php echo $form->textField($model,'site', array('value' => $model->site, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'site'); ?>
                    </div>

                    <div class="left">
                        <?php echo $form->labelEx($model,'req_OGRN', array('style'=>"text-align: right;margin-right:20px;") ); ?>
                        <?php echo $form->textField($model,'req_OGRN', array('value' => $model->req_OGRN, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'req_OGRN'); ?>
                    </div>
        </div>
	<div class="line1">
                    <div class="left">
                        <?php echo $form->labelEx($model,'req_BIK'); ?>
                        <?php echo $form->textField($model,'req_BIK', array('value' => $model->req_INN, 'class'=>"medium") ); ?>
                        <?php echo $form->error($model,'req_BIK'); ?>
                    </div>
        </div>  
        <div class="line1">
                    <p>
                        <?php echo $form->labelEx($model,'ind_authorized_capital'); ?>
                        <?php echo $form->textField($model,'ind_authorized_capital', array('value' => $model->ind_authorized_capital, 'class'=>"medium", 'alt'=>"cc") ); ?>

<script type="text/javascript" >
  (function($){
    // call setMask function on the document.ready event
      $(function(){
        $('input:text').setMask();
      }
    );
  })(jQuery);
</script>
                        <?php echo $form->error($model,'ind_authorized_capital'); ?>
                    </p>

                    <p>
                        <?php echo $form->labelEx($model,'ind_assets'); ?>
                        <?php echo $form->textField($model,'ind_assets', array('value' => $model->ind_assets, 'class'=>"medium", 'alt'=>"cc") ); ?>
                        <?php echo $form->error($model,'ind_assets'); ?>
                    </p>

                    <p>
                        <?php echo $form->labelEx($model,'ind_deposits'); ?>
                        <?php echo $form->textField($model,'ind_deposits', array('value' => $model->ind_deposits, 'class'=>"medium", 'alt'=>"cc") ); ?>
                        <?php echo $form->error($model,'ind_deposits'); ?>
                    </p>
         </div>        
        
                    <div class="upload_logo">
                            <div style="margin-left:10px;"><span style="font-size:large;">Лицензия:</span></div>
                            <?php 
                            if(isset($bankLicences) && $bankLicences)
                            foreach($bankLicences as $k=>$bl){ ?>
                            <table id="bank_licence_t<?=$k?>">
                               <tr>
                                <td style="vertical-align:bottom;">
                                    <div class="del_new_logo">
                                        <div id="licence<?=$k?>">
                                            <div id="bank_licence_on<?=$k?>" style="<?=((empty($bl->data) || is_null($bl->data))?'display:none;':'')?>;">
                                                <a id="bank_licence<?=$k?>" href="<?=Yii::app()->baseUrl.$bl->data?>" target="_blank">Посмотреть файл</a>
                                            </div>
                                        </div>                                        
                                    <div class="header">Наименование | 
                                    <?=CHtml::ajaxLink($modelLicence->getAttributeLabel('delete'), 
                                                            Yii::app()->createUrl('/banks/licencedelete'), 
                                                            array('type'=>'GET','data'=>array('id'=>$model->id,'licence_id'=>$bl->id),'success'=>'function(){$("#bank_licence_t'.$k.'").remove();}'),
                                                            array('onclick'=>'if (!confirm("Вы уверены что хотите удaлить эту лицензию ?")){return false;}',
                                                                    'class'=>'delete'))?></div>
                                    <div class="uploadinputsblock">
                                            <div style="float:left;">
                                                <input type="text" name="licence[<?=$bl->id?>]" class="medium" style="width:320px;" value="<?=$bl->title?>" />
                                            </div>
                                            <div style="float:left;">
                                                <? $this->widget('ext.EAjaxUpload.EAjaxUpload',
                                                    array(
                                                        'id'=>'licencePic'.$k,
                                                        'config'=>array(
                                                            'action'=>Yii::app()->createUrl('/banks/licenceupload/id/'.$model->id.'/licence_id/'.$bl->id),
                                                            'allowedExtensions'=>array('jpg','gif','png','jpeg'),//array("jpg","jpeg","gif","exe","mov" and etc...
                                                            'sizeLimit'=>200*1024,// maximum file size in bytes
                                                            'minSizeLimit'=>10*1024,// minimum file size in bytes
                                                            //'onSubmit' => "js:function(id, fileName){ alert ('submit'); }",
                                                            //'onProgress' => "js:onProgress: function(id, fileName, loaded, total){ alert('progress') }",
                                                            'onComplete'=>"js:function(id, fileName, responseJSON){ 
                                                                                if (responseJSON.success){
                                                                                    alert(responseJSON.message);
                                                                                    $('#bank_licence_on".$k."').css('display','block');
                                                                                }else{
                                                                                    alert(responseJSON.error);
                                                                                }
                                                                           }",
                                                            'onCancel' => "js:function(id, fileName){ alert('cancel') }",
                                                            'messages'=>array(
                                                                     'typeError'=>Yii::t('app', "{file} Имеет недопустимое расширение. Только {extensions} разрешены."),
                                                                     'sizeError'=>"{file} слишком большой, максимальный размер файла {sizeLimit}.",
                                                                     'minSizeError'=>"{file} слишком маленький, минимальный азмер файла {minSizeLimit}.",
                                                   //                  'emptyError'=>"{file} is empty, please select files again without it.",
                                                   //                  'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
                                                                    ),
                                                             'showMessage'=>"js:function(message){ alert(message); }" ,
                                                        'buttonName'=>'Прикрепить файл',
                                                        'width'=>'125px'
                                                  )
                                                )); ?>
                                           </div>
                                        </div>
                                    </div>

                                <br>
                            </td>
                        </tr>
                    </table>                
                    <?php } //end foreach of licences?>
                    <p><?=CHtml::ajaxButton($modelLicence->getAttributeLabel('add_licence'), 
                                                                        Yii::app()->createUrl('/banks/addlicence/'), 
                                                                        array('type'=>'GET','data'=>array('bank_id'=>$model->id),
                                                                            'complete'=>'function(xmlHttp) {
                                                                                            if (xmlHttp.code != 200) {
                                                                                              top.location.href = "'.Yii::app()->createUrl('/banks/adminedit/id/'.$model->id.'/scrolldown').'";
                                                                                            }                                                                       
                                                                                        }'),
                                                                        array('style'=>'height:30px;width:150px;font-weight: normal;border:1px solid red;','id'=>'add_licence_but'))?>
                    </p>
                    </div>
<!-----------------------end------------------->        
        
        
	<div class="line">
		<?php echo CHtml::link(
            $model->isNewRecord ? Yii::t('app', 'Создать') : Yii::t('app', 'Сохранить'),
            'javascript:void(0)', 
            array('class'=>"button green", 'style'=>"opacity: 1;", 'onclick' => '$("#bankedit").submit();')); ?>
            <button type="submit" onclick="window.location.replace('<?=$this->createUrl("banks/")?>');return false; " class="blue small">
                <span><?= Yii::t('app', 'Отмена')?></span>
            </button>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->
</div>
<script>
// scroll down back to Licence area if Licence was added
$(function(){scrolldown()});
function scrolldown(){
    var montage=window.location.href.split("/");
    if(montage[montage.length-1]=='scrolldown') {
        self.scrollTo(0,10000);
    }
}
</script>